package com.pan.action.chain.impl;

import com.pan.action.chain.ChainAction;
import com.pan.domain.Dot;
import com.pan.show.record.Record;
import com.pan.utils.ApplicationConfig;
import com.pan.utils.MyMouseInfo;
import com.pan.utils.ShortcutKeyConfig;

import javax.swing.*;
import java.awt.*;
import java.util.Set;

public class MarkMouseAction extends ChainAction<Set<String>> {
    private String[] targetKeys;

    {
        String shortcutKey = ShortcutKeyConfig.INSTANCE.getMarkMouseKey();
        targetKeys = shortcutKey.trim().split("\\+");
    }

    public MarkMouseAction() {
    }

    @Override
    public void handle(Set<String> keys) {
//        debug
//        keys.stream().forEach(System.out::println);
        for (String k:targetKeys){
            if (!keys.contains(k)) return;
        }
        Point point = MyMouseInfo.INSTANCE.getPoint();//MouseInfo.getPointerInfo().getLocation();
        int x = (int) point.getX();
        int y = (int) point.getY();
        Dot dot = new Dot(x,y);


        //show
        Record record = ApplicationConfig.INSTANCE.getRecordFactory().getRecord();
        record.setContent(dot.toString());
        record.display();

//        JFrame frame = new JFrame();
//        frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
//        frame.setTitle("Mouse Position");
//        JLabel label = new JLabel();
//        label.setText(dot.toString());
//        frame.add(label);
//        frame.pack();
//        frame.setVisible(true);

    }

}
